import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'


export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: '财务报表', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'table',
        name: 'Table',
        component: () => import('@/views/Example/table/index'),
        meta: { title: 'Table', icon: 'table' }
      },
      {
        path: 'tree',
        name: 'Tree',
        component: () => import('@/views/Example/tree/index'),
        meta: { title: 'Tree', icon: 'tree' }
      }
    ]
  },

  {
    path: '/user',
    component: Layout,
    meta: { title: '用户模块', icon: 'el-icon-user-solid' },
    children: [
      /*{
        path: 'index',
        name: 'Form',
        component: () => import('@/views/user/index'),
        meta: { title: 'index', icon: 'form' }
      },*/
      {
        path: 'administrators',
        name: 'Administrators',
        component: () => import('@/views/user/Administrators'),
        meta: { title: '管理员列表', icon: 'table' }
      },
      {
        path: 'customer',
        name: 'Customer',
        component: () => import('@/views/user/Customer'),
        meta: { title: '客户列表', icon: 'table' }
      },
      {
        path: 'merchant',
        name: 'Merchant',
        component: () => import('@/views/user/Merchant'),
        meta: { title: '商家列表', icon: 'table' }
      }
    ]
  },

  {
    path: '/goods',
    component: Layout,
    meta: {
      title: '库存模块',
      icon: 'el-icon-box'
    },
    children: [
      {
        path: 'card',
        name: 'Card',
        component: () => import('@/views/Goods/Card'),
        meta: { title: '标签列表', icon: 'table' }
      },
      {
        path: 'rule',
        name: 'Rule',
        component: () => import('@/views/Goods/Rule'),
        meta: { title: '规则列表', icon: 'table' }
      },
      {
        path: 'activity',
        name: 'Activity',
        component: () => import('@/views/Goods/Activity'),
        meta: { title: '活动列表', icon: 'table' }
      },
      {
        path: 'salegoods',
        name: 'Salegoods',
        component: () => import('@/views/Goods/Salegoods'),
        meta: { title: '商品列表', icon: 'table' }
      },
    ]
  },

  {
    path: '/order',
    component: Layout,
    meta: { title: '订单模块', icon: 'el-icon-shopping-cart-full' },
    children: [
      {
        path: 'orderstate',
        name: 'Orderstate',
        component: () => import('@/views/Order/Orderstate'),
        meta: { title: '订单列表', icon: 'table' }
      },
      {
        path: 'shippingaddress',
        name: 'Shippingaddress',
        component: () => import('@/views/Order/Shippingaddress'),
        meta: { title: '收货地址列表', icon: 'table' }
      }
    ]
  },

  {
    path: '/Info',
    component: Layout,
    meta: { title: '信息模块', icon: 'el-icon-folder-opened' },
    children: [
      {
        path: 'log',
        name: 'Log',
        component: () => import('@/views/Info/Log'),
        meta: { title: '日志列表', icon: 'table' }
      },
      {
        path: 'introduce',
        name: 'Introduce',
        component: () => import('@/views/Info/Introduce'),
        meta: { title: '介绍列表', icon: 'table' }
      },
      {
        path: 'picture',
        name: 'Picture',
        component: () => import('@/views/Info/Picture'),
        meta: { title: '图片列表', icon: 'table' }
      },
      {
        path: 'collectionex',
        name: 'Collectionex',
        component: () => import('@/views/Info/Collectionex'),
        meta: { title: '收藏列表', icon: 'table' }
      },
      {
        path: 'comments',
        name: 'Comments',
        component: () => import('@/views/Info/Comments'),
        meta: { title: '评论列表', icon: 'table' }
      },
      {
        path: 'reply',
        name: 'Reply',
        component: () => import('@/views/Info/Reply'),
        meta: { title: '回复评论列表', icon: 'table' }
      },
      {
        path: 'history',
        name: 'History',
        component: () => import('@/views/Info/History'),
        meta: { title: '浏览历史列表', icon: 'table' }
      },
      {
        path: 'merchantmessage',
        name: 'Merchantmessage',
        component: () => import('@/views/Info/Merchantmessage'),
        meta: { title: '商家消息列表', icon: 'table' }
      },
      {
        path: 'work',
        name: 'Work',
        component: () => import('@/views/Info/Work'),
        meta: { title: '任务列表', icon: 'table' }
      },
      {
        path: 'workstate',
        name: 'Workstate',
        component: () => import('@/views/Info/Workstate'),
        meta: { title: '任务状态列表', icon: 'table' }
      }
    ]
  },

  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://gitee.com/wode98k_admin/spring-cloud-mall/tree/develop/',
        meta: { title: 'External Link', icon: 'link' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
